package com.yc.jiushujie.jsj_index.web;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.swing.*;
import java.util.Map;

@RestController

public class IndexAction {
    @Resource
    IOrderAction orderAction;
    @Resource
    IUserAction   userAction;
    @GetMapping("/")
    ModelAndView index(ModelAndView mav){
        mav.setViewName("index");
        mav.addObject("haos",orderAction.queryHao());
        mav.addObject("hotsou",orderAction.queryHotsou());
        mav.addObject("news",userAction.queryNew());
        mav.addObject("lastlogin",userAction.queryLastlogin());
        mav.addObject("hotshudian",userAction.queryHotshudian());
        mav.addObject("hotuser",userAction.queryHotuser());
        return mav;
    }
    @GetMapping("/{page}.htm")
    ModelAndView toPage(@PathVariable String page, ModelAndView mav){
        mav.setViewName(page);
        return mav;

    }
    @GetMapping("/book_{id}")
    ModelAndView book(@PathVariable int id,
                      @RequestParam(defaultValue ="1") int page , @RequestParam(defaultValue ="10") int size , ModelAndView mav){

        mav.addObject("jsjbook",orderAction.findById(id));
        mav.addObject("news",userAction.queryNew());
//         mav.addObject("owner",orderAction.queryUserByBid(id));
        mav.addObject("book",orderAction.getowner(id));

        mav.setViewName("book");
  return mav;
    }
    @GetMapping("/sell")
    ModelAndView sell(ModelAndView mav,
                      @RequestParam(defaultValue = "1") int page,@RequestParam(defaultValue = "10") int size ){
        mav.setViewName("sell");
        mav.addObject("news",userAction.queryNew());
        mav.addObject("lastlogin",userAction.queryLastlogin());
        mav.addObject("hotshudian",userAction.queryHotshudian());
        mav.addObject("hotuser",userAction.queryHotuser());
        mav.addObject("cate",orderAction.queryCategory());
        mav.addObject("allbook",orderAction.queryAllBook(page,size));

        return mav;
    }
    @GetMapping("/user")
        ModelAndView user(ModelAndView mav,@RequestParam String account){
       mav.setViewName("user");
        return mav;
        }

}
